#!/bin/sh

. STlsVars

SKIPIFNOT USING_EXAMPLES_EXAMPLE_MODULE

#########################################
# CERTIFICATE SETUP
#

# produce the certificates to use
HOSTNAME=`hostname`

# snmptrapd
CAPTURE $NSCERT gencert -t snmptrapd   --cn $HOSTNAME $NSCERTARGS
TRAPDFP=`$NSCERT showcerts --fingerprint --brief snmptrapd  $NSCERTARGS`
CHECKVALUEISNT "$TRAPDFP" "" "generated fingerprint for snmptrapd certificate"

# snmpd
CAPTURE $NSCERT gencert -t snmpd   --cn $HOSTNAME $NSCERTARGS
SERVERFP=`$NSCERT showcerts --fingerprint --brief snmpd  $NSCERTARGS`
CHECKVALUEISNT "$SERVERFP" "" "generated fingerprint for snmpd certificate"

# user
CAPTURE $NSCERT gencert -t snmpapp --cn 'testuser'  $NSCERTARGS
TESTUSERFP=`$NSCERT showcerts --fingerprint --brief snmpapp $NSCERTARGS`
CHECKVALUEISNT "$TESTUSERFP" "" "generated fingerprint for testuser certificate"

#########################################
# Configuration

# snmpd
CONFIGAGENT trapsess     -T localCert=$TESTUSERFP -T peerCert=$TRAPDFP  ${SNMP_TRANSPORT_SPEC}:${SNMP_TEST_DEST}${SNMP_SNMPTRAPD_PORT}
CONFIGAGENT trapsess -Ci -T localCert=$TESTUSERFP -T peerCert=$TRAPDFP  ${SNMP_TRANSPORT_SPEC}:${SNMP_TEST_DEST}${SNMP_SNMPTRAPD_PORT}
CONFIGAGENT '[snmp]' localCert $SERVERFP
CONFIGAGENT 	     certSecName      9  $TESTUSERFP     --cn
CONFIGAGENT          rwuser           -s tsm testuser

# snmptrapd
CONFIGTRAPD '[snmp]' localCert $TRAPDFP
CONFIGTRAPD 	     certSecName      9  $TESTUSERFP     --cn
CONFIGTRAPD 	     authuser         log -s tsm testuser authpriv

# general

#
# Begin test
#

STARTTRAPD

AGENT_FLAGS="$AGENT_FLAGS -Dexample,header_generic"
STARTAGENT

CAPTURE "snmpset -v3 -T peerCert=snmpd -T localCert=snmpapp -On -t 3 -r 0 $SNMP_FLAGS $SNMP_TRANSPORT_SPEC:$SNMP_TEST_DEST$SNMP_SNMPD_PORT .1.3.6.1.4.1.2021.254.8.0 i 1"

STOPAGENT

STOPTRAPD

CHECKTRAPDCOUNT 2 "life the universe and everything"

FINISHED
